package com.itjason.controller;

import com.itjason.dto.NationUploadDataDTO;
import com.itjason.dto.Question;
import com.itjason.exceptionhandler.ResponseException;
import com.itjason.po.GameOption;
import com.itjason.po.OptionItem;
import com.itjason.service.GameOptionService;
import com.itjason.vo.WxQuestion;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 游戏界面控制层
 */

@Api(value = "管理员管理接口")
@RestController
@RequestMapping("/wx/game")

public class WxGameController {

    @Autowired
    private GameOptionService gameOptionService;

    /**
     * 随机获取题目
     * @return
     */
    @ApiOperation("游戏题目获取")
    @GetMapping("/game")
    public List<WxQuestion> getGame(){
        return gameOptionService.getQuestions();
    }


    @ApiOperation("游戏答题")
    @PostMapping("/answer")
    public ResponseException answer(@RequestBody OptionItem optionItem){
        return gameOptionService.answer(optionItem)==true?ResponseException.success():ResponseException.error("200","答案错误！！！");
    }


    @ApiOperation("题目添加")
    @PostMapping("/add")
    public ResponseException addQuestion( @RequestBody Question question){
        return gameOptionService.addQuestion(question);
    }


    @ApiOperation("题目删除")
    @GetMapping("/delete")
    public ResponseException delete(@RequestParam("gameId") Integer id){
        return gameOptionService.delete(id);
    }

    @ApiOperation("题目修改")
    @PostMapping("/update")
    public ResponseException update(@RequestBody Question question){
        return gameOptionService.updateQuestionInfo(question);
    }

    @ApiOperation("管理员查询题目")
    @GetMapping("/query")
    private List<GameOption> query(){
        List<GameOption> list = gameOptionService.query().list();
        return list;
    }

    @GetMapping("/get")
    private List<OptionItem> get(@RequestParam("gameId") Integer id){
        return gameOptionService.queryOptionItem(id);
    }

    @PostMapping("/file")
    public ResponseException uploadNationVoice(@RequestParam String gameFile, @RequestParam MultipartFile multipartFile) {
        NationUploadDataDTO nationUploadDataDTO = new NationUploadDataDTO();
        nationUploadDataDTO.setNationFlag(gameFile);
        nationUploadDataDTO.setMultipartFile(multipartFile);
        return gameOptionService.uploadFile(nationUploadDataDTO);
    }

}
